package manong.controller;

import com.github.pagehelper.PageInfo;

import manong.beans.User;
import manong.constant.ServerResponse;
import manong.beans.Stu;
import manong.service.IStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
	@RequestMapping("/Stu/")
	public class StuController {
	    @Autowired
	    private IStuService iStuService;

	    @RequestMapping("add")
	    public ServerResponse<String> add(String studentName, String className,Integer sno,String mark,String studentPhone,String speciality) {
	        return iStuService.add(studentName,className,sno,mark,studentPhone,speciality);
	    }

	    @RequestMapping("del")
	    public ServerResponse<String> del(Integer id) {
	        return iStuService.del(id);
	    }

	    @RequestMapping("update")
	    public ServerResponse<String> update(Integer id, String studentName,String className,Integer sno,String mark,String studentPhone,String speciality) {
	        return iStuService.update(id,studentName,className,sno,mark,studentPhone,speciality);
	    }

	    @RequestMapping("find")
	    public ServerResponse<Stu> find(Integer id) {
	        return iStuService.find(id);
	    }

	    @RequestMapping("findAll")
	    public ServerResponse<PageInfo<Stu>> findAll(Integer pageNum, Integer pageSize) {
	        return iStuService.findAll(pageNum, pageSize);
	    }

		@RequestMapping("findByClassRom")
		public ServerResponse<PageInfo<Stu>> findByClassRom(Integer pageNum, Integer pageSize, HttpSession session) {
			//从session域中取出当前登录用户的信息
			User user = (User) session.getAttribute("user");
			//取出学号，查询学生对象取出班级id，根据班级id查询对应的同班同学信息
			String Sno = user.getMark();
			return iStuService.findByClassRom(Sno,pageNum, pageSize);
		}



	}




